import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { FormBuilder } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd';
import { CenterService } from '@core/routes-services/center.service';

@Component({
  selector: 'app-otc-center-otc-center-detail',
  templateUrl: './otc-center-detail.component.html',
})
export class OtcCenterDetailComponent implements OnInit {

  id: any = 0;// 默认 0
  entity: any = {};
  isLoading: boolean = true;
  index:any = 0
  constructor(    private router: Router,
                  private route: ActivatedRoute,
                  private fb: FormBuilder,
                  private centerService: CenterService,
                  public message: NzMessageService,) {
  }

  ngOnInit() {
    this.route.queryParams.forEach((params: Params) => {
      let id =  +params['id'];
      if(!isNaN(id)) {
        this.id = +params['id'];
        this.initEntity();
      }
    });
  }

  initEntity(){
    this.centerService.detail(this.id).then((res) => {
      if (res.status.toString().startsWith('20')) {
        this.entity = res.data;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error);
      this.isLoading = false;
    });
  }
  close(e) {
    console.log(e);
    if(e!=false){
      this.message.success("保存成功")
      this.entity = e;
    }
  }
}
